// CSE 142, Winter 2008, Marty Stepp // // This program demonstrates a method with a loop that returns a boolean result. import java.util.*; // for Random public class LuckySeven { public static void main(String[] args) { Random rand = new Random(); // call my method to test its results if (seven(rand)) { System.out.println(" I got a lucky 7!!"); } else { System.out.println(" I didn't get a 7. :-("); } } public static boolean seven(Random rand) { for (int i = 1; i <= 10; i++) { // pick a random number int lotto = rand.nextInt(30) + 1; System.out.print(lotto + " "); if (lotto == 7) { // if I get a 7, I can stop immediately return true; } } // if I ever get down here, // there was never a 7 return false; } }